Undefined method `add' on a cucumber step that usually works.

Posted by Josiah Kiehl on Stack Overflow See other posts from Stack Overflow or by Josiah Kiehl
Published on 2010-03-12T00:49:27Z Indexed on 2010/03/12 0:57 UTC
Read the original article Hit count: 319

Filed under:
|

I have a path defined:

when /the admin home\s?page/
  "/admin/"

I have scenario that is passing:

  Scenario: Let admins see the admin homepage
    Given "pojo" is logged in
    And "pojo" is an "admin"
    And I am on the admin home page
    Then I should see "Hi there."

And I have a scenario that is failing:

  Scenario: Review flagged photo
    Given "pojo" is logged in
    And "pojo" is an "admin"
  ...bunch of steps that create stuff in the database...
    And I am on the admin home page
    Then ... the rest of the steps

The step that fails in the second one is "And I am on the admin home page" which passes just fine in the first scenario.

Here's the error I get:

And I am on the admin home page                 # features/step_definitions/web_steps.rb:18
  undefined method `add' for {}:Hash (NoMethodError)
  ./app/controllers/admin_controller.rb:13:in `index'
  ./app/controllers/admin_controller.rb:11:in `each'
  ./app/controllers/admin_controller.rb:11:in `index'
  /usr/lib/ruby/1.8/benchmark.rb:308:in `realtime'
  ./features/step_definitions/web_steps.rb:19:in `/^(?:|I )am on (.+)$/'
  features/admin.feature:52:in `And I am on the admin home page'

This is very odd... why would it be fine in the first case, and not in the second where the only difference are a bunch of steps that create records in the db?

[edit]

Here's the add stuff to database step:

Given /^there is a "([^\"]*)" with the following:$/ do |model, table|
  model.constantize.create!(table.rows_hash)
end

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about cucumber